import axios from '@/router/axios';
import {getToken} from '@/util/auth'
import website from '@/config/website';
import {Base64} from 'js-base64';
import {Message} from 'element-ui'
export default {
  menus: [ // 菜单配置
    'head', // 标题
    'bold', // 粗体
    'fontSize', // 字号
    'fontName', // 字体
    'italic', // 斜体
    'underline', // 下划线
    'strikeThrough', // 删除线
    'foreColor', // 文字颜色
    'backColor', // 背景颜色
    'link', // 插入链接
    'list', // 列表
    'justify', // 对齐方式
    'emoticon', // 表情
    'image', // 插入图片
    'undo', // 撤销
    'redo', // 重复
  ],
  colors: ['#000000','#333333','#232323','#666666', '#eeece0', '#1c487f', '#4d80bf', '#c24f4a', '#8baa4a', '#7b5ba1', '#46acc8', '#f9963b', '#ffffff', '#BD8DED'],
  fontNames: [
    '宋体',
    '微软雅黑',
    'Arial',
    'Tahoma',
    'Verdana'
  ],
  zIndex: 2,
  uploadImgShowBase64: true,
  //上传图片
  customUploadImg: function (files, insert) {
    let formData = new FormData();
    formData.append("file", files[0])
    axios({
      url: '/api/blade-file/file/upload',
      method: 'post',
      timeout: 36000000, // 默认上传时长为1小时
      headers: {
        "Content-Type": "multipart/form-data",
        "Authorization": `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}`,
        "Blade-Auth": 'bearer ' + getToken()
      },
      data: formData,
    }).then((res) => {
      insert(res.data.data[0].fileUrl)
    }).catch(err => {
      Message({
        type: 'error',
        message: err.message
      })
    })
  },
  //上传视频
  customUploadVideo: function (formData, insert) {
    axios({
      url: '/api/blade-file/file/upload',
      method: 'post',
      timeout: 36000000, // 默认上传时长为1小时
      headers: {
        "Content-Type": "multipart/form-data",
        "Authorization": `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}`,
        "Blade-Auth": 'bearer ' + getToken()
      },
      data: formData,
    }).then((res) => {
      insert(res.data.data[0].fileUrl)
    }).catch(err => {
      Message({
        type: 'error',
        message: err.message
      })
    })
  },
}
